package itstudio.instructor.ui;

import itstudio.instructor.adapter.LibraryListAdapter;
import itstudio.instructor.entity.BorrowBook;
import itstudio.instructor.widget.DynamicBox;
import itstudio.instructor.xlistview.XListView;
import itstudio.instructor.xlistview.XListView.IXListViewListener;
import java.util.ArrayList;
import java.util.List;
import com.easemob.chatuidemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;



/**   
* @Description: 综合统计球道杆
* @author wang   
* @date 2015-2-11 下午6:32:17 
* @version V1.0   
*/
public class LibraryActivity extends Activity implements  IXListViewListener {
	
	private XListView xlistView;
	private DynamicBox box;
	private View top_back;
	private LibraryListAdapter adapter;
	
	 @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_library);
		findViews();
		init();
	}

	protected void findViews() {
        xlistView = (XListView) findViewById(R.id.xlistView);
        top_back =  findViewById(R.id.top_back);
	}

	protected void init() {
		// TODO Auto-generated method stub
		xlistView.setXListViewListener(this);
		adapter= new LibraryListAdapter(this, null);
		xlistView.setAdapter(adapter);
		xlistView.setPullLoadEnable(false);
		getBooks();
		box = new DynamicBox(this,xlistView);
		box.showLoadingLayout();
		
		top_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

	private void getBooks() {

		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				adapter.appendToList(testData());
			}
		}, 2000);
	}

	private List<BorrowBook> testData() {
		List<BorrowBook> bookList = new ArrayList<BorrowBook>();
		BorrowBook b1= new BorrowBook();
		b1.setName("《美好古董衣店》");
		b1.setAuthor("[美]斯特范尼.莱曼 著");
		b1.setStartDate("2015-03-04");
		b1.setLeftDate("-1天17时25分");
		b1.setState(BorrowBook.OUT_OF_DATE);
		b1.setPicuri("drawable://"+R.drawable.t_book_meihaogudong);
		bookList.add(b1);
		BorrowBook b2= new BorrowBook();
		b2.setName("《百年孤独》");
		b2.setAuthor("加西亚.马尔克斯著");
		b2.setStartDate("2015-01-25");
		b2.setLeftDate("3天21时45分");
		b2.setState(BorrowBook.NORMAL);
		b2.setPicuri("drawable://"+R.drawable.t_book_bainianguodu);
		bookList.add(b2);
		BorrowBook b3= new BorrowBook();
		b3.setName("《围城》");
		b3.setAuthor("钱钟书 著");
		b3.setStartDate("2015-02-13");
		b3.setLeftDate("28天13时56分");
		b3.setState(BorrowBook.CAN_COUNTINE);
		b3.setPicuri("drawable://"+R.drawable.t_book_weicheng);
		bookList.add(b3);
		return bookList;
	}
	@Override
	public void onRefresh() {
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				xlistView.stopRefresh();
			}
		}, 2000);
	}

	@Override
	public void onLoadMore() {
		
	}

}

